#!/bin/sh
# Copyright 1986-2010 QAD Inc., Carpinteria, CA, USA.                        
# All rights reserved worldwide.  This is an unpublished work.               
# $Revision: $
#                                                                            
# $Id: $
# 
# This script will run a compile program that uses compile.lst as input
#============================================================================

export DLC=/qad/progress/dlc102b01
export PROMSGS=$DLC/promsgs

if [ `dirname $0` = "." ];
then
   CURRENTDIR=`pwd`
else
   CURRENTDIR=`dirname $0`
fi

COMPILEALL=0
COMPUSER=""
for args in "$@"
do
   if [ "$args" = "all" ]
   then
      COMPILEALL=2
      break;
   fi

   if [ "$args" = "jvz" ]
   then 
      COMPUSER="jvz"
      COMPILEALL=1
      break;
   fi
   if [ "$args" = "ss8" ]
   then 
      COMPUSER="ss8"
      COMPILEALL=1
      break;
   fi
   if [ "$args" = "ycm" ]
   then 
      COMPUSER="ycm"
      COMPILEALL=1
      break;
   fi
done

export ROOT=${CURRENTDIR%/*}

if [ "$ROOT" = "/qad/local/sandbox/team/mrc93" ] || [ "$ROOT" = "/qad/local/sandbox/user/dev/mrc93" ] ; then
   RUN="run devel"
else
   RUN=""
fi

export PUB=/qad/local/sandbox/team/mrc93
export PROPATH=$ROOT,$ROOT/reports/data-source,$ROOT/build/work/pro/com/mfgpro,$ROOT/build/work/pro,$ROOT/build/work/config,$ROOT/build/work/dist,$ROOT/build/work/dist/us/bbi,/qad/mfgpro/93/snap93sp5h/stageobj/lib/qra.pl,/qad/mfgpro/93/snap93sp5h/stageobj/proxyobj/proxy.pl,$ROOT/proxysrc,$ROOT/src,$PUB/build/work/pro/com/mfgpro,$PUB/build/work/pro,$PUB/build/work/config,$PUB/build/work/dist,$PUB/build/work/dist/us/bbi,$PUB/proxysrc,$PUB/src,.,$ROOT/reports/

TEMPLIST=$ROOT/temp.lst
if [ -f $TEMPLIST ]; then
   rm -f $TEMPLIST
fi

if [ -f $ROOT/compile.log ]; then
   rm -f $ROOT/compile.log
fi

cd $ROOT/reports/data-source
for i in `ls`
do
   if [ ! -f $ROOT/build/work/pro/com/qad/shell/report/reports/$i ];
   then
      $RUN cp -p $i $ROOT/build/work/pro/com/qad/shell/report/reports
      if [ "${i##*.}" = "p" ]; then
	 echo $i >> $TEMPLIST
      fi
   fi
   if [[ `stat $i|grep Modify|cut -d: -f2-|cut -d. -f1` > `stat $ROOT/build/work/pro/com/qad/shell/report/reports/$i|grep Modify|cut -d: -f2-|cut -d. -f1` ]]; then
      $RUN cp -p $i $ROOT/build/work/pro/com/qad/shell/report/reports
      if [ "${i##*.}" = "p" ]; then
	 echo $i >> $TEMPLIST
      fi
   fi
done

if [ $COMPILEALL -eq 2 ]; then
   $RUN ls QAD_*.p > $TEMPLIST
fi

if [ $COMPILEALL -eq 1 ]; then
   $RUN grep -l $COMPUSER QAD_*.p > $TEMPLIST
fi

if [ ! -f $ROOT/build/compile.pf ]; then
   $RUN sed "s/newyork/qaddb/" $ROOT/build/work/config/desktop.pf > $ROOT/build/compile.pf
fi

cd $ROOT

if [ ! -f $ROOT/compile.lst ]; then
   $RUN mv $TEMPLIST $ROOT/compile.lst
fi

if [ $COMPILEALL -eq 2 ]; then
   $RUN mv $TEMPLIST $ROOT/compile.lst
fi
echo $COMPILEALL $COMPUSER
if [ $COMPILEALL -eq 1 ]; then
   $RUN mv $TEMPLIST $ROOT/compile.lst
fi


$RUN $DLC/bin/_progres \
-rereadnolock -pf $ROOT/build/compile.pf \
-p $ROOT/build/compile.p  \
-cpinternal ISO8859-1 -cpstream ISO8859-1

less $ROOT/compile.log
